<?php

use think\migration\Migrator;
use think\migration\db\Column;

class AddTemplateData extends Migrator
{
    public function up() {
        // template 推广模板表 增加周边游、出行加油 推广模板
        $table = 'template';
        $name=@PRODUCT_SERV_TYPE[PRODUCT_TRAVEL_OIL_SERV]['name'];
        $list = \think\facade\Db::table($table)->where('template_name', $name)->findOrEmpty();
        $data['created_at']=date("Y-m-d H:i:s");
        if (empty($list)) {
            $data['template_name']=$name;
            $data['pre_url']="/topup/travel/index";
            $data['template_img']="https://hfcs.dmjvip.com/template/travel.jpg";
            \think\facade\Db::name($table)->insert($data);
        }

        $name=@PRODUCT_SERV_TYPE[PRODUCT_AROUND_SHOP_SERV]['name'];
        $list = \think\facade\Db::table($table)->where('template_name', $name)->findOrEmpty();
        if (empty($list)) {
            $data['template_name']=$name;
            $data['pre_url']="/topup/around/index";
            $data['template_img']="https://hfcs.dmjvip.com/template/around.jpg";
            \think\facade\Db::name($table)->insert($data);
        }
    }

    public function down() {
        $attr=[@PRODUCT_SERV_TYPE[PRODUCT_TRAVEL_OIL_SERV]['name'],@PRODUCT_SERV_TYPE[PRODUCT_AROUND_SHOP_SERV]['name']];
        \think\facade\Db::table('template')->where('template_name', "in",$attr)->delete();
    }
}
